### End User configurable options ###
SHELL = @SHELL@

# Installation directories ( not being used here )
prefix           = @prefix@
exec_prefix      = @exec_prefix@
bindir           = @bindir@
includedir       = @includedir@
libdir           = @libdir@

# Build directories
libbuild_dir     = @libbuild_dir@
binbuild_dir     = @binbuild_dir@
includebuild_dir = @includebuild_dir@
top_srcdir       = @top_srcdir@
srcdir           = @srcdir@

TRACE_HOME       = $(top_srcdir)/..
TRACE_INCDIR     = $(TRACE_HOME)/src/logformat/trace
TRACE_SRCDIR     = $(TRACE_HOME)/src/logformat/trace

# Use VPATH so logformat/trace/*.c(h) do NOT need to be here.
@VPATH@@VPATH_EXTRA@

# Define the TRACE-API shared library name and utility program names here
LIB_TRACE        = @LIBSO_PREFIX@TraceInput.la
PGM_PRINT        = @TRACE_NAME@_print@EXEEXT@
PGM_CHECK        = @TRACE_NAME@_check_timeorder@EXEEXT@

# Define the TRACE-API implementation here, only variable needs to be changed
IMPL_CSRC        = trace_impl.c

# the next 3 lines should NOT be changed 
CSRC             = $(IMPL_CSRC) logformat_trace_InputLog.c
CSRC4T           = $(IMPL_CSRC) trace_print.c
CSRC4E           = $(IMPL_CSRC) trace_check_timeorder.c

OBJ              = $(CSRC:.c=.@OBJEXT@)
LOBJ             = $(CSRC:.c=.lo)
OBJ4T            = $(CSRC4T:.c=.@OBJEXT@)
OBJ4E            = $(CSRC4E:.c=.@OBJEXT@)

CC               = @CC@
LDF              = @CC@ @LIBSO_CFLAGS@ @CFLAGS@ @LDFLAGS@
INSTALL          = @INSTALL@ 
LIBTOOL          = $(SHELL) ../libtool
EXPORT_SYMBOLS   = @EXPORT_SYMBOLS@
RM               = @RM@

JNI_INC          = @JNI_INC@
CFLAGS           = -I.. $(JNI_INC) -I$(TRACE_INCDIR) @LIBSO_CFLAGS@ @CFLAGS@
LTLDFLAGS        = -module -no-undefined -avoid-version @LIBSO_LDFLAGS@

# memory leak checker
MEMLIBS          = @DEBUG_LIBS@

.SUFFIXES:
.SUFFIXES: .h .c .@OBJEXT@ .lo .la @EXEEXT@

.c.@OBJEXT@:
	$(CC) $(CFLAGS) -c $<

.c.lo:
	$(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -c $<

ALL: $(libbuild_dir)/$(LIB_TRACE)
	$(MAKE) $(MAKEOPTS) $(binbuild_dir)/$(PGM_PRINT)
	$(MAKE) $(MAKEOPTS) $(binbuild_dir)/$(PGM_CHECK)

$(libbuild_dir)/$(LIB_TRACE): $(LOBJ)
	if [ "$(EXPORT_SYMBOLS)" = "yes" ] ; then \
	    $(LIBTOOL) --mode=link $(LDF) $(LTLDFLAGS) -o $(LIB_TRACE) $(LOBJ) \
	               -export-symbols $(srcdir)/JavaTraceInput.sym \
	               -rpath $(libbuild_dir) ; \
	else \
	    $(LIBTOOL) --mode=link $(LDF) $(LTLDFLAGS) -o $(LIB_TRACE) $(LOBJ) \
	               -rpath $(libbuild_dir) ; \
	fi
	$(LIBTOOL) --mode=install $(INSTALL) $(LIB_TRACE) $(libbuild_dir)
	$(LIBTOOL) --finish $(libbuild_dir)

INSTALL_LIBSO: $(LOBJ)
	if [ "$(EXPORT_SYMBOLS)" = "yes" ] ; then \
	    $(LIBTOOL) --mode=link $(LDF) $(LTLDFLAGS) -o $(LIB_TRACE) $(LOBJ) \
	               -export-symbols $(srcdir)/JavaTraceInput.sym \
	               -rpath $(LIBDIR) ; \
	else \
	    $(LIBTOOL) --mode=link $(LDF) $(LTLDFLAGS) -o $(LIB_TRACE) $(LOBJ) \
	               -rpath $(LIBDIR) ; \
	fi
	$(LIBTOOL) --mode=install $(INSTALL) $(LIB_TRACE) $(DESTDIR)$(LIBDIR)
	$(LIBTOOL) --finish $(LIBDIR)

$(binbuild_dir)/$(PGM_PRINT): $(OBJ4T)
	$(LDF) -o $@ $(OBJ4T) $(MEMLIBS)

$(binbuild_dir)/$(PGM_CHECK): $(OBJ4E)
	$(LDF) -o $@ $(OBJ4E) $(MEMLIBS)

clean:
	@-$(RM) *.@OBJEXT@ *.lo *.la

realclean: clean
	$(LIBTOOL) --mode=uninstall $(RM) $(libbuild_dir)/$(LIB_TRACE)
	@-$(RM) $(binbuild_dir)/$(PGM_PRINT) $(binbuild_dir)/$(PGM_CHECK)
	@-$(RM) -r .libs

distclean: realclean
	@-$(RM) Makefile
